package com.roshan.service.impl;

import java.io.Serializable;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.transaction.annotation.Transactional;

import com.roshan.dao.BaseDAO;
import com.roshan.domain.BaseDomain;
import com.roshan.service.BaseService;

@SuppressWarnings("unchecked")
public class BaseServiceImpl<T extends BaseDomain, S extends Serializable> implements BaseService<T, S> {

    protected Logger logger = Logger.getLogger(BaseServiceImpl.class);

    protected BaseDAO<T, S> dao;

    public BaseServiceImpl() {
        // No content
    }

    public BaseServiceImpl(BaseDAO<T, S> baseDao) {
        this.dao = baseDao;
    }

    @Override
    @Transactional
    public boolean exists(S id) {
        return this.dao.exists(id);
    }

    @Override
    @Transactional
    public T get(S id) {
        return this.dao.findById(id);
    }

    @Override
    @Transactional
    public List<T> getAll() {
        return this.dao.findAll();
    }

    @Override
    @Transactional
    public void remove(S id) {
        this.dao.delete(id);

    }

    @Override
    @Transactional
    public T save(T entity) {
        return this.dao.save(entity);
    }

}
